package com.zhongkai.web.control.config;

import javax.servlet.http.*;

import org.apache.struts.action.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhongkai.tools.ValidatorCodeTool;

@Controller

public class DisplayValidateCodeControl
{
	@RequestMapping(value="/code.do")
  public void execute(HttpServletRequest request,HttpServletResponse response)
  {
    ValidatorCodeTool vct = new ValidatorCodeTool(response, request);
    String picWidth = request.getParameter("picWidth");
    String picHeight = request.getParameter("picHeight");
    String fontSize = request.getParameter("fontSize");
    String fontDistance = request.getParameter("fontDistance");
    String fontX = request.getParameter("fontX");
    String fontY = request.getParameter("fontY");
    String codeLength = request.getParameter("codeLength");
    String sessionName = request.getParameter("sessionName");
    String charset  = request.getParameter("charset");
    if (picWidth!= null && !picWidth.trim().equals(""))
    {
      vct.setPicWidth(new Integer(picWidth).intValue());
    }
    else
    {
      vct.setPicWidth(90);
    }
    if (picHeight!= null && !picHeight.trim().equals(""))
    {
      vct.setPicHeight(new Integer(picHeight).intValue());
    }
    else
    {
      vct.setPicHeight(25);
    }

    if (codeLength!= null && !codeLength.trim().equals(""))
    {
      vct.setCodeLength(new Integer(codeLength).intValue());
    }
    else
    {
      vct.setCodeLength(6);
    }
    if (fontSize!= null && !fontSize.trim().equals(""))
    {
      vct.setFontSize(new Integer(fontSize).intValue());
    }
    else
    {
      vct.setFontSize(18);
    }
    if (sessionName!= null && !sessionName.trim().equals(""))
    {
      vct.setSessionName(sessionName);
    }
    else
    {
      vct.setSessionName("validatecode");
    }
    if (fontDistance != null && !fontDistance.trim().equals(""))
    {
      vct.setFontDistance(new Integer(fontDistance).intValue());
    }
    else
    {
      vct.setFontDistance(13);
    }
    if (fontX != null && !fontX.trim().equals(""))
    {
      vct.setFontX(new Integer(fontX).intValue());
    }
    else
    {
      vct.setFontX(6);
    }

    if (fontY != null && !fontY.trim().equals(""))
    {
      vct.setFontY(new Integer(fontY).intValue());
    }
    else
    {
      vct.setFontY(20);
    }
    if(charset!=null && !charset.trim().equals(""))
    {
     vct.setCharset(charset);
    }
    else
    {
     vct.setCharset("a-zA-Z0-9");
    }
    vct.setColorEndValue(100);
    vct.setColorEndValue(250);
    vct.displayValidatorCode();
  }
}
